﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace Core.Extensions
{
    public static class ParseExtensions
    {
        public static String[] TrimQuotes(this String[] arr)
        {
            return arr.Select(str => str.Trim('"')).ToArray();
        }

        public static int ParseInt(this String str)
        {
            return Convert.ToInt32(str);
        }

        public static DateTime ParseDateTime(this String str)
        {
            DateTime dt;
            if (!DateTime.TryParse(str, out dt))
                throw new FormatException("Invalid timestamp format");
            return dt;
        }

        public static IPAddress ParseIpAddress(this String str)
        {
            IPAddress ip;
            if (!IPAddress.TryParse(str, out ip))
                throw new FormatException("Invalid IPv4 address format");
            return ip;
        }
    }
}
